package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.bean.GmA;
import com.bw.bean.gmB;
import com.bw.bean.GmC;
import com.bw.bean.GmD;
import com.bw.service.GmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GmController {
    @Autowired
    GmService service;

    @RequestMapping("listA")
    public JSONObject listA(){
        List<GmA> GmAS = service.listA();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject object = new JSONObject();

        JSONArray arr1 = new JSONArray();
        for (GmA gmA : GmAS) {
            arr1.add(gmA.getA());
        }
        object.put("categories",arr1);

        JSONArray arr2 = new JSONArray();
        JSONObject arr2Obj = new JSONObject();

        arr2Obj.put("name","第二大类");
        JSONArray arr2ObjArr = new JSONArray();
        for (GmA gmA : GmAS) {
            arr2ObjArr.add(gmA.getB());
        }
        arr2Obj.put("data",arr2ObjArr);

        arr2.add(arr2Obj);
        object.put("series",arr2);

        jsonObject.put("data",object);

        return jsonObject;
    }
    @RequestMapping("listB")
    public JSONObject listB(){
        List<gmB> gmBS = service.listB();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray arr = new JSONArray();
        for (gmB gmB : gmBS) {
            JSONObject obj = new JSONObject();
            obj.put("name", gmB.getA());
            obj.put("value", gmB.getB());
            arr.add(obj);
        }
        jsonObject.put("data",arr);

        return jsonObject;
    }
    @RequestMapping("listC")
    public JSONObject listC(){
        List<GmC> gmCS = service.listC();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray arr = new JSONArray();
        for (GmC gmC : gmCS) {
            JSONObject obj = new JSONObject();
            obj.put("name", gmC.getA());
            obj.put("value", gmC.getB());
            arr.add(obj);
        }
        jsonObject.put("data",arr);

        return jsonObject;
    }
    @RequestMapping("listD")
    public JSONObject listD(){
        List<GmD> gmDS = service.listD();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject object = new JSONObject();

        JSONArray arr1 = new JSONArray();
        JSONObject arr1Obj1 = new JSONObject();
        arr1Obj1.put("name","品牌名字");
        arr1Obj1.put("id","a");
        arr1.add(arr1Obj1);
        JSONObject arr1Obj2 = new JSONObject();
        arr1Obj2.put("name","性别");
        arr1Obj2.put("id","b");
        arr1.add(arr1Obj2);
        JSONObject arr1Obj3 = new JSONObject();
        arr1Obj3.put("name","总金额");
        arr1Obj3.put("id","c");
        arr1.add(arr1Obj3);

        object.put("columns",arr1);

        JSONArray arr2 = new JSONArray();
        for (GmD gmD : gmDS) {
            JSONObject obj = new JSONObject();
            obj.put("a", gmD.getA());
            obj.put("b", gmD.getB());
            obj.put("c", gmD.getC());
            arr2.add(obj);
        }
        object.put("rows",arr2);

        jsonObject.put("data",object);

        return jsonObject;
    }

}
